package com.bw.base.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.sql.Time
import java.util.concurrent.TimeUnit

object RetrofitUtils {
    fun getRetrofit():Retrofit{
        val httpClient = OkHttpClient.Builder()
            .readTimeout(5, TimeUnit.SECONDS)
            .callTimeout(5, TimeUnit.SECONDS)
            .writeTimeout(5, TimeUnit.SECONDS)
            .addInterceptor{
                val token = SPUtils.getInstance().getString("token")
                val request = it.request().newBuilder().addHeader("token",token).build()
                it.proceed(request)
            }
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .build()
        val retrofit = Retrofit.Builder()
            .client(httpClient)
            .baseUrl("http://10.161.9.80:7012")
            .addConverterFactory(GsonConverterFactory.create())
            .build()
        return retrofit
    }
}